package com.jeomo.masterdata.starter.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeomo.masterdata.starter.entity.Level;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 崔贺
 */
@Mapper
public interface LevelMapper extends BaseMapper<Level> {

    @Select("select * FROM member_level WHERE start_flag = 1 ORDER BY level_code ")
    List<Level> getAllLevels();

    @Select("select * FROM member_level WHERE start_flag = 1  AND org_code=#{orgCode} ORDER BY level_code ")
    List<Level> getAllLevel(String orgCode);

    @Select("select * FROM member_level where org_code=#{orgCode} ORDER BY level_code ")
    List<Level> getAllLevelList(String orgCode);

    /**
     * 查询高一级的会员等级
     * @param orgCode
     * @param levelCode
     * @return
     */
    @Select("select * FROM member_level WHERE start_flag = 1 AND org_code=#{orgCode} AND level_code>#{levelCode} ORDER BY level_code limit 1")
    Level getNextLevel(@Param("orgCode") String orgCode, @Param("levelCode") String levelCode);

    /**
     * 查询低一级的会员等级
     * @param orgCode
     * @param levelCode
     * @return
     */
    @Select("select * FROM member_level WHERE start_flag = 1 AND org_code=#{orgCode} AND level_code<#{levelCode} ORDER BY level_code desc limit 1")
    Level getPrevLevel(@Param("orgCode") String orgCode, @Param("levelCode") String levelCode);

    /**
     * 获取最小的会员级别
     * @param orgCode
     * @return
     */
    @Select("select * FROM member_level WHERE start_flag = 1 AND org_code=#{orgCode} ORDER BY level_code limit 1")
    Level getMinLevel(@Param("orgCode") String orgCode);

}
